<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/css/public.css" media="all">
</head>
<body>
<form class="layui-form" action="" style="position: absolute;top: 30px">
    <div class="layui-form-item">
        <label class="layui-form-label">电影名</label>
        <div class="layui-input-inline" style="width: 410px">
            <input type="text" name="name" required  lay-verify="required" placeholder="请输入电影名" autocomplete="off" class="layui-input" id="editname">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">上映年份</label>
        <div class="layui-input-inline" style="width: 410px">
            <input type="text" name="year" required  lay-verify="required" placeholder="请输入年份" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">类型</label>
        <div class="layui-input-block">
            <input type="checkbox" name="Adventure" title="Adventure">
            <input type="checkbox" name="Animation" title="Animation">
            <input type="checkbox" name="Children" title="Children">
        </div>
        <div class="layui-input-block">
            <input type="checkbox" name="Comedy" title="Comedy">
            <input type="checkbox" name="Fantasy" title="Fantasy">
            <input type="checkbox" name="Romance" title="Romance">
        </div>
        <div class="layui-input-block">
            <input type="checkbox" name="Drama" title="Drama">
            <input type="checkbox" name="Action" title="Action">
            <input type="checkbox" name="Crime" title="Crime">
        </div>
        <div class="layui-input-block">
            <input type="checkbox" name="Thriller" title="Thriller">
            <input type="checkbox" name="IMAX" title="IMAX">
            <input type="checkbox" name="Sci-Fi" title="Sci-Fi">
        </div>
        <div class="layui-input-block">
            <input type="checkbox" name="Musical" title="Musical">
            <input type="checkbox" name="Mystery" title="Mystery">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="addmovieformbts">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script src="/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>

<script>
    layui.use(['jquery','form'],function () {
        var form = layui.form,
            $ = layui.jquery;
        form.on('submit(addmovieformbts)', function(data){
            var str
            var t=1
            $('input[type=checkbox]:checked').each(function() {
                if(t==1)
                {
                    str=$(this)[0].name
                    t++
                }
                else {
                    str=str+"|"+$(this)[0].name
                    t++
                }
            });

            $.ajax({
                type:'post',
                data:{
                    name:data.field.name+'('+data.field.year+')',
                    genres:str
                },
                dataType:'json',
                url:'/system/movie/add',
                success:function (data) {
                    if(data.code=="0"){
                        layer.msg("添加成功",{time:500},function () {
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        })

                    }
                }
            })
            return false
        });
    })

</script>
</body>
</html>